/*
 * Copyright 2012 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package test.fox.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 类GetPost.java的实现描述：TODO 类实现描述
 * 
 * @author husong 2012-10-27 下午7:07:59
 */
public class GetPost extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = -3026322308086194742L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse)
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/html;charset=UTF-8");

        out.println("<HTML>");
        out.println("<BODY>");
        // 客户使用的协议 HTTP/1.1
        out.println("<br/>Protocol");
        out.println(req.getProtocol());
        out.println(req.getContextPath());
        // 客户提交的信息长度
        out.println(req.getContentLength());

        out.println(req.getHeader("User-Agent"));
        out.println(req.getHeader("accept-encodeing"));

        // session
        HttpSession session = req.getSession(true);
        session.setAttribute("name", "husong");
        session.setAttribute("sex", "1");
        out.println(session.getId());
        out.println(session.getAttribute("name"));
        session.removeAttribute("sex");
        out.println(session.getAttribute("sex"));

        out.println("</BODY>");
        out.println("</HTML>");
    }

    /*
     * (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse)
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doPost(req, resp);
    }

}
